import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Random;

public class StudentJFrame extends JFrame implements MouseListener {
    ArrayList<Group> CLASS = new ArrayList<>();

    ArrayList<aClass> RealCLASS = new ArrayList<>();

    aClass first = new aClass(1);
    aClass second = new aClass(2);

    Student[] arr = new Student[6];

    JMenuItem AddClass = new JMenuItem("添加班级");
    JMenuItem DeleteClass = new JMenuItem("删除班级");
    JMenuItem LookClass = new JMenuItem("查看信息");
    JMenuItem AddStudent = new JMenuItem("添加学生");
    JMenuItem DeleteStudent = new JMenuItem("删除学生");
    JMenuItem SetStudent = new JMenuItem("修改学生信息");
    JMenuItem LookStudent = new JMenuItem("查看学生信息");
    JMenuItem AddGroup = new JMenuItem("添加小组");
    JMenuItem DeleteGroup = new JMenuItem("删除小组");
    JMenuItem SetGroup = new JMenuItem("修改小组信息");
    JMenuItem LookGroup = new JMenuItem("查看小组信息");
    JMenuItem NameStudent = new JMenuItem("小组内点学生");
    JMenuItem NameGroup = new JMenuItem("随机抽小组");
    JMenuItem NameClass = new JMenuItem("班级内点学生");
    JMenuItem Have = new JMenuItem("出勤记录");
    JMenuItem Answer = new JMenuItem("回答记录");
    JMenuItem Grade = new JMenuItem("小组评分");
    JMenuItem Look = new JMenuItem("查看成绩");

    JTextField input = new JTextField();
    JTextField input1 = new JTextField();
    JTextField input2 = new JTextField();
    JTextField input3 = new JTextField();
    JTextField input4 = new JTextField();
    JTextField input5 = new JTextField();
    JTextField input6 = new JTextField();
    JTextField input7 = new JTextField();
    JTextField input8 = new JTextField();
    JTextField input9 = new JTextField();
    JTextField input10 = new JTextField();
    JTextField input11=new JTextField();
    JTextField input12=new JTextField();
    JTextField input13=new JTextField();
    JTextField input14=new JTextField();
    JTextField input15=new JTextField();
    JTextField input16=new JTextField();

    JLabel information = new JLabel();

    JButton confirm = new JButton("确认");
    JButton confirm1 = new JButton("确认");
    JButton confirm2 = new JButton("确认");
    JButton confirm3 = new JButton("确认");
    JButton confirm4 = new JButton("确认");
    JButton confirm5 = new JButton("确认");
    JButton confirm6 = new JButton("确认");
    JButton confirm7 = new JButton("确认");
    JButton confirm8 = new JButton("确认");
    JButton confirm9 = new JButton("确认");
    JButton confirm10 = new JButton("确认");
    JButton confirm11 = new JButton("确认");
    JButton confirm12 = new JButton("确认");

    JLabel point=new JLabel();
    JLabel point1=new JLabel();
    JLabel point2=new JLabel();
    JLabel point3=new JLabel();

    public StudentJFrame() {

        InitInformation();
        InitJFrame();
        InitMenu();

        this.setVisible(true);
    }

    public void InitMenu() {
        JMenuBar jMenuBar = new JMenuBar();

        JMenu ClassMenu = new JMenu("班级管理");
        JMenu StudentMenu = new JMenu("学生管理");
        JMenu GroupMenu = new JMenu("小组管理");
        JMenu NameMenu = new JMenu("点名");
        JMenu GradeMenu = new JMenu("成绩管理");

        ClassMenu.add(AddClass);
        ClassMenu.add(DeleteClass);
        ClassMenu.add(LookClass);
        StudentMenu.add(AddStudent);
        StudentMenu.add(DeleteStudent);
        StudentMenu.add(SetStudent);
        StudentMenu.add(LookStudent);
        GroupMenu.add(AddGroup);
        GroupMenu.add(DeleteGroup);
        GroupMenu.add(SetGroup);
        GroupMenu.add(LookGroup);
        NameMenu.add(NameGroup);
        NameMenu.add(NameStudent);
        NameMenu.add(NameClass);
        GradeMenu.add(Have);
        GradeMenu.add(Answer);
        GradeMenu.add(Grade);
        GradeMenu.add(Look);

        jMenuBar.add(ClassMenu);
        jMenuBar.add(StudentMenu);
        jMenuBar.add(GroupMenu);
        jMenuBar.add(NameMenu);
        jMenuBar.add(GradeMenu);

        AddClass.addMouseListener(this);
        DeleteClass.addMouseListener(this);
        LookClass.addMouseListener(this);
        AddStudent.addMouseListener(this);
        DeleteStudent.addMouseListener(this);
        SetStudent.addMouseListener(this);
        LookStudent.addMouseListener(this);
        AddGroup.addMouseListener(this);
        DeleteGroup.addMouseListener(this);
        SetGroup.addMouseListener(this);
        LookGroup.addMouseListener(this);
        NameStudent.addMouseListener(this);
        NameGroup.addMouseListener(this);
        NameClass.addMouseListener(this);
        Have.addMouseListener(this);
        Answer.addMouseListener(this);
        Grade.addMouseListener(this);
        Look.addMouseListener(this);


        this.setJMenuBar(jMenuBar);
    }

    public void InitJFrame() {
        this.addMouseListener(this);

        this.setTitle("学生管理系统");

        this.setSize(800, 500);

        this.setAlwaysOnTop(true);

        this.setDefaultCloseOperation(3);

        this.setLocationRelativeTo(null);

        this.setLayout(null);

    }

    public void InitInformation() {
        RealCLASS.add(first);
        RealCLASS.add(second);

        arr[0] = new Student("孟流虎", "2023015479", first);
        arr[1] = new Student("陈碧玉", "2023015478", first);
        arr[2] = new Student("雷君", "2023015477", first);
        arr[3] = new Student("余胜军", "2023015476", first);
        arr[4] = new Student("麻花疼", "2023015475", first);
        arr[5] = new Student("码云", "2023015474", first);

        CLASS.add(new Group(1, arr[0], arr[1]));
        CLASS.add(new Group(2, arr[2], arr[3]));
        CLASS.add(new Group(3, arr[4], arr[5]));

    }

    public void InitImage() {
        this.getContentPane().removeAll();
        this.getContentPane().repaint();
    }


    @Override
    public void mousePressed(MouseEvent e) {
        Object obj = e.getSource();
        if (obj == AddClass) {
            InitImage();
            point.setBounds(5,100,120,30);
            point.setText("输入要添加的班级：");
            this.getContentPane().add(point);

            input.setBounds(120, 100, 300, 30);
            input.repaint(100, 100, 300, 30);
            this.getContentPane().add(input);
            confirm.setBounds(430, 100, 90, 30);
            confirm.addMouseListener(this);
            this.getContentPane().add(confirm);
        } else if (obj == DeleteClass) {
            InitImage();
            point.setBounds(5,100,120,30);
            point.setText("输入要删除的班级：");
            this.getContentPane().add(point);
            input.setBounds(120, 100, 300, 30);
            input.repaint(100, 100, 300, 30);
            this.getContentPane().add(input);
            confirm1.setBounds(430, 100, 90, 30);
            confirm1.addMouseListener(this);
            this.getContentPane().add(confirm1);
        } else if (obj == LookClass) {
            InitImage();
            for (int i = 0; i < RealCLASS.size(); i++) {
                JLabel tmp = new JLabel("班级：" + RealCLASS.get(i).getaClass());
                tmp.setBounds(0, i * 21, 60, 20);
                this.getContentPane().add(tmp);
            }
        } else if (obj == AddStudent) {
            InitImage();
            point.setBounds(5,100,140,30);
            point.setText("输入要添加学生的学号：");
            this.getContentPane().add(point);
            point1.setBounds(5,140,140,30);
            point1.setText("输入要添加学生的姓名：");
            this.getContentPane().add(point1);
            point2.setBounds(5,180,140,30);
            point2.setText("输入要添加学生的班级：");
            this.getContentPane().add(point2);
            input1.setBounds(140, 100, 300, 30);
            input1.repaint(100, 100, 300, 30);
            this.getContentPane().add(input1);
            input2.setBounds(140, 140, 300, 30);
            input2.repaint(100, 140, 300, 30);
            this.getContentPane().add(input2);
            input3.setBounds(140, 180, 300, 30);
            input3.repaint(100, 180, 300, 30);
            this.getContentPane().add(input3);
            confirm2.setBounds(450, 180, 90, 30);
            confirm2.addMouseListener(this);
            this.getContentPane().add(confirm2);
        } else if (obj == DeleteStudent) {
            InitImage();
            point.setBounds(5,100,140,30);
            point.setText("输入要删除学生的学号：");
            this.getContentPane().add(point);
            input.setBounds(140, 100, 300, 30);
            input.repaint(140, 100, 300, 30);
            this.getContentPane().add(input);
            confirm3.setBounds(450, 100, 90, 30);
            confirm3.addMouseListener(this);
            this.getContentPane().add(confirm3);
        }else if(obj==SetStudent){
            InitImage();
            point.setBounds(5,100,150,30);
            point.setText("输入要修改学生的原学号：");
            this.getContentPane().add(point);

            point1.setBounds(5,140,150,30);
            point1.setText("输入要修改学生的新学号：");
            this.getContentPane().add(point1);

            point2.setBounds(5,180,150,30);
            point2.setText("输入要修改学生的新姓名：");
            this.getContentPane().add(point2);

            point3.setBounds(5,220,150,30);
            point3.setText("输入要修改学生的新班级：");
            this.getContentPane().add(point3);

            input1.setBounds(150, 100, 300, 30);
            input1.repaint(150, 100, 300, 30);
            this.getContentPane().add(input1);
            input2.setBounds(150, 140, 300, 30);
            input2.repaint(150, 140, 300, 30);
            this.getContentPane().add(input2);
            input3.setBounds(150, 180, 300, 30);
            input3.repaint(150, 180, 300, 30);
            this.getContentPane().add(input3);
            input4.setBounds(150, 220, 300, 30);
            input4.repaint(150, 220, 300, 30);
            this.getContentPane().add(input4);
            confirm4.setBounds(460, 220, 90, 30);
            confirm4.addMouseListener(this);
            this.getContentPane().add(confirm4);
        }else if(obj==LookStudent){
            InitImage();
            int count=0;
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] != null) {
                    JLabel tmp = new JLabel("班级为"+arr[i].getaClass().getaClass()+"班,"+
                            "学号为" + arr[i].getId() + ",姓名为" + arr[i].getName()+" 出勤:"+
                            arr[i].attend+" 答题:"+arr[i].answer);
                    tmp.setBounds(0, i * 21, 400, 20);
                    this.getContentPane().add(tmp);
                    System.out.println();
                }else{
                    count++;
                }
            }
            if(count==arr.length){
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("当前还没有学生");
                this.getContentPane().add(information);
                System.out.println("当前还没有学生！");
            }
        }else if(obj==AddGroup){
            InitImage();
            point.setBounds(5,100,140,30);
            point.setText("输入第一个成员的学号：");
            this.getContentPane().add(point);

            point1.setBounds(5,140,140,30);
            point1.setText("输入第二个成员的学号：");
            this.getContentPane().add(point1);

            input5.setBounds(140, 100, 300, 30);
            input5.repaint(140, 100, 300, 30);
            this.getContentPane().add(input5);
            input6.setBounds(140, 140, 300, 30);
            input6.repaint(140, 140, 300, 30);
            this.getContentPane().add(input6);
            confirm5.setBounds(450, 140, 90, 30);
            confirm5.addMouseListener(this);
            this.getContentPane().add(confirm5);
        }else if(obj==DeleteGroup){
            InitImage();
            point.setBounds(5,140,140,30);
            point.setText("输入要删除小组的编号：");
            this.getContentPane().add(point);
            input7.setBounds(140, 140, 300, 30);
            input7.repaint(140, 140, 300, 30);
            this.getContentPane().add(input7);
            confirm6.setBounds(450, 140, 90, 30);
            confirm6.addMouseListener(this);
            this.getContentPane().add(confirm6);
        }else if(obj==SetGroup){
            InitImage();
            point.setBounds(15,100,160,30);
            point.setText("输入要修改的小组的编号：");
            this.getContentPane().add(point);

            point1.setBounds(5,140,170,30);
            point1.setText("输入新小组第一个成员学号：");
            this.getContentPane().add(point1);

            point2.setBounds(5,180,170,30);
            point2.setText("输入新小组第二个成员学号：");
            this.getContentPane().add(point2);

            input8.setBounds(170, 100, 300, 30);
            input8.repaint(170, 100, 300, 30);
            this.getContentPane().add(input8);
            input9.setBounds(170, 140, 300, 30);
            input9.repaint(170, 140, 300, 30);
            this.getContentPane().add(input9);
            input10.setBounds(170, 180, 300, 30);
            input10.repaint(170, 180, 300, 30);
            this.getContentPane().add(input10);
            confirm7.setBounds(480, 180, 90, 30);
            confirm7.addMouseListener(this);
            this.getContentPane().add(confirm7);
        }else if(obj==LookGroup){
            InitImage();
            for (int i = 0; i < RealCLASS.size(); i++) {
                JLabel tmp = new JLabel("第" + (i + 1) + "组:"+"\n"+
                        "小组第一个成员是学号" + CLASS.get(i).member1.getId() + "，姓名" + CLASS.get(i).member1.getName()+"\n"+
                        ",小组第二个成员是学号" + CLASS.get(i).member2.getId() + "，姓名" + CLASS.get(i).member2.getName());
                tmp.setBounds(0, i * 31, 600, 30);
                this.getContentPane().add(tmp);
            }
        }else if(obj==NameGroup){
            InitImage();
            Random r = new Random();
            int index = r.nextInt(CLASS.size());

            JLabel tmp = new JLabel("点到的小组为" + (index + 1) + "组");
            tmp.setBounds(200, 100, 200, 40);
            this.getContentPane().add(tmp);

            JLabel tmp1=new JLabel("小组第一个成员是学号" + CLASS.get(index).member1.getId() + "，姓名" + CLASS.get(index).member1.getName());
            tmp1.setBounds(150, 141, 300, 40);
            this.getContentPane().add(tmp1);

            JLabel tmp2=new JLabel("小组第二个成员是学号" + CLASS.get(index).member2.getId() + "，姓名" + CLASS.get(index).member2.getName());
            tmp2.setBounds(150, 182, 300, 40);
            this.getContentPane().add(tmp2);

        }else if(obj==NameStudent){
            InitImage();
            point.setBounds(5,140,120,30);
            point.setText("输入小组编号：");
            this.getContentPane().add(point);

            input11.setBounds(100, 140, 300, 30);
            input11.repaint(100, 140, 300, 30);
            this.getContentPane().add(input11);
            confirm8.setBounds(430, 140, 90, 30);
            confirm8.addMouseListener(this);
            this.getContentPane().add(confirm8);
        }else if(obj==NameClass){
            InitImage();
            point.setBounds(5,140,120,30);
            point.setText("输入班级：");
            this.getContentPane().add(point);

            input12.setBounds(100, 140, 300, 30);
            input12.repaint(100, 140, 300, 30);
            this.getContentPane().add(input12);
            confirm9.setBounds(430, 140, 90, 30);
            confirm9.addMouseListener(this);
            this.getContentPane().add(confirm9);
        }else if(obj==Have){
            InitImage();
            point.setBounds(25,140,120,30);
            point.setText("输入学号：");
            this.getContentPane().add(point);

            input13.setBounds(120, 140, 300, 30);
            input13.repaint(120, 140, 300, 30);
            this.getContentPane().add(input13);
            confirm10.setBounds(430, 140, 90, 30);
            confirm10.addMouseListener(this);
            this.getContentPane().add(confirm10);
        }else if(obj==Answer){
            InitImage();
            point.setBounds(25,140,120,30);
            point.setText("输入学号：");
            this.getContentPane().add(point);

            input14.setBounds(120, 140, 300, 30);
            input14.repaint(120, 140, 300, 30);
            this.getContentPane().add(input14);
            confirm11.setBounds(430, 140, 90, 30);
            confirm11.addMouseListener(this);
            this.getContentPane().add(confirm11);
        }else if(obj==Grade){
            InitImage();
            point.setBounds(25,100,120,30);
            point.setText("输入小组编号：");
            this.getContentPane().add(point);

            point1.setBounds(25,140,120,30);
            point1.setText("输入评分：");
            this.getContentPane().add(point1);

            input15.setBounds(120, 100, 300, 30);
            input15.repaint(120, 100, 300, 30);
            this.getContentPane().add(input15);
            input16.setBounds(120, 140, 300, 30);
            input16.repaint(120, 140, 300, 30);
            this.getContentPane().add(input16);
            confirm12.setBounds(430, 140, 90, 30);
            confirm12.addMouseListener(this);
            this.getContentPane().add(confirm12);
        }else if(obj==Look){
            InitImage();
            for (int i = 0; i < CLASS.size()-1; i++) {
                JLabel tmp = new JLabel("第" + (i + 1) + "组，"+"成绩为"+CLASS.get(i).score);
                tmp.setBounds(0, i * 31, 400, 30);
                this.getContentPane().add(tmp);
            }
        }

        if (obj == confirm) {
            int a = getNum(input.getText());
            if (!JudgeClass(RealCLASS, a)) {
                InitImage();
                aClass t = new aClass(a);
                RealCLASS.add(t);
                System.out.println("添加成功");

                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("添加成功");
                this.getContentPane().add(information);

            } else {
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("班级已存在");
                this.getContentPane().add(information);

                System.out.println("班级已存在");
            }
        } else if (obj == confirm1) {
            if (RealCLASS.isEmpty()) {
                InitImage();
                System.out.println("没有班级");

                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("没有班级");
                this.getContentPane().add(information);
            }
            int a = getNum(input.getText());
            if (JudgeClass(RealCLASS, a)) {
                InitImage();
                DeleteRealCLASS(RealCLASS, a);
                DeleteClass(arr, a);
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("删除成功");
                this.getContentPane().add(information);

            } else {
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("班级不存在");
                this.getContentPane().add(information);
            }
        } else if (obj == confirm2) {
            InitImage();
            if (Judge(arr) != arr.length) {
                for (int i = 0; i < arr.length; i++) {
                    if (arr[i] == null) {
                        arr[i] = new Student();
                        if (JudgeOnly(arr, input1.getText())) {
                            arr[i].setId(input1.getText());
                            arr[i].setName(input2.getText());
                            int tmp = getNum(input3.getText());
                            if (JudgeClass(RealCLASS, tmp)) {
                                aClass tmp1 = new aClass(tmp);
                                arr[i].setaClass(tmp1);
                                InitImage();
                                information.setBounds(320, 150, 100, 100);
                                information.setText("添加成功");
                                System.out.println("添加成功");
                                break;
                            } else {
                                InitImage();
                                information.setBounds(320, 150, 100, 100);
                                information.setText("班级不存在");
                                this.getContentPane().add(information);
                                System.out.println("班级不存在");
                                break;
                            }
                        } else {
                            InitImage();
                            information.setBounds(320, 150, 100, 100);
                            information.setText("已存在");
                            this.getContentPane().add(information);
                            System.out.println("已存在");
                            break;
                        }
                    }
                }
            }
            //数组满了的话
            else {
                if (JudgeOnly(arr, input1.getText())) {
                    arr = Creat(arr);
                    arr[arr.length - 1].setId(input1.getText());
                    arr[arr.length - 1].setName(input2.getText());
                    int tmp = getNum(input3.getText());
                    if (JudgeClass(RealCLASS, tmp)) {
                        aClass tmp1 = new aClass(tmp);
                        arr[arr.length - 1].setaClass(tmp1);
                        InitImage();
                        information.setBounds(320, 150, 100, 100);
                        information.setText("添加成功");
                        this.getContentPane().add(information);
                        System.out.println("添加成功");

                    } else {
                        InitImage();
                        information.setBounds(320, 150, 100, 100);
                        information.setText("班级不存在");
                        this.getContentPane().add(information);
                        System.out.println("班级不存在");
                    }
                } else {
                    InitImage();
                    information.setBounds(320, 150, 100, 100);
                    information.setText("已存在");
                    this.getContentPane().add(information);
                    System.out.println("已存在");
                }
            }
        } else if (obj == confirm3) {
            System.out.println("输入要删除学生的学号");
            String inputTmp =input.getText();
            boolean flag1 = true;
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] != null) {
                    if (arr[i].getId().equals(inputTmp)) {
                        arr[i] = null;
                        InitImage();
                        information.setBounds(320, 150, 100, 100);
                        information.setText("删除成功");
                        this.getContentPane().add(information);
                        System.out.println("删除成功");
                        flag1 = false;
                        break;
                    }
                }
            }
            if (flag1) {
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("不存在的学生");
                this.getContentPane().add(information);
                System.out.println("不存在的学生");
            }
        }else if(obj==confirm4){
            boolean flag1 = true;
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] != null) {
                    if (arr[i].getId().equals(input1.getText())) {
                        flag1 = false;
                        if (JudgeOnly(arr, input2.getText())) {

                            arr[i].setId(input2.getText());
                            arr[i].setName(input3.getText());
                            int tmp=getNum(input4.getText());
                            if (JudgeClass(RealCLASS, tmp)) {
                                aClass tmp1 = new aClass(tmp);
                                arr[i].setaClass(tmp1);
                                InitImage();
                                information.setBounds(320, 150, 100, 100);
                                information.setText("修改成功");
                                this.getContentPane().add(information);
                                System.out.println("success");
                                break;
                            } else {
                                InitImage();
                                information.setBounds(320, 150, 100, 100);
                                information.setText("班级不存在");
                                this.getContentPane().add(information);
                                System.out.println("班级不存在");
                                break;
                            }
                        }
                        else {
                            InitImage();
                            information.setBounds(320, 150, 100, 100);
                            information.setText("修改后的学号已存在");
                            this.getContentPane().add(information);
                            System.out.println("修改后的学号已存在");
                            break;
                        }
                    }
                }
            }
            if(flag1){
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("学生不存在");
                this.getContentPane().add(information);
                System.out.println("学生不存在");
            }
        }else if(obj==confirm5){
            boolean flag = true;
            System.out.println("请输入第一个小组成员学号");
            String first1 = input5.getText();
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] != null) {
                    if (arr[i].getId().equals(first1)) {
                        flag = false;
                        System.out.println("请输入第二个小组成员学号");
                        String second1 = input6.getText();
                        for (int j = 0; j < arr.length; j++) {
                            if (arr[j] != null) {
                                if (arr[j].getId().equals(second1)) {
                                    Group tmp = new Group(CLASS.size(), arr[i], arr[j]);
                                    CLASS.add(tmp);
                                    InitImage();
                                    information.setBounds(320, 150, 100, 100);
                                    information.setText("添加成功");
                                    this.getContentPane().add(information);
                                    System.out.println("添加成功");
                                    break;
                                }
                            }
                        }
                    }
                }

            }
            if (flag) {
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("输入的人不存在");
                this.getContentPane().add(information);
                System.out.println("输入的人不存在");
            }
        }else if(obj==confirm6){
            int index = getNum(input7.getText());
            if (index < CLASS.size() + 1) {
                CLASS.remove(index - 1);
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("删除成功");
                this.getContentPane().add(information);
                System.out.println("删除成功");
            } else {
                InitImage();
                information.setBounds(320, 150, 100, 100);
                information.setText("小组不存在");
                this.getContentPane().add(information);
                System.out.println("小组不存在");
            }
        }else if(obj==confirm7) {
            int index =getNum(input8.getText());
            if (index < CLASS.size() + 1 && index >= 0) {
                boolean flag = true;
                String first1 = input9.getText();
                for (int i = 0; i < arr.length; i++) {
                    if (arr[i] != null) {
                        if (arr[i].getId().equals(first1)) {
                            flag = false;
                            String second1 = input10.getText();
                            for (int j = 0; j < arr.length; j++) {
                                if (arr[j] != null) {
                                    if (arr[j].getId().equals(second1)) {
                                        Group tmp = new Group(CLASS.size(), arr[i], arr[j]);
                                        CLASS.set(index - 1, tmp);
                                        InitImage();
                                        information.setBounds(320, 150, 100, 100);
                                        information.setText("修改成功");
                                        this.getContentPane().add(information);
                                        System.out.println("修改成功");
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (flag) {
                    InitImage();
                    information.setBounds(320, 150, 100, 100);
                    information.setText("输入的人不存在");
                    this.getContentPane().add(information);
                    System.out.println("输入的人不存在");
                }
            }
        }else if(obj==confirm8){
            Random r = new Random();
            int s = getNum(input11.getText());
            int index = r.nextInt(2);
            if (s <= CLASS.size() && s >= 0) {
                if (index == 0) {
                    InitImage();
                    information.setBounds(320, 150, 300, 100);
                    information.setText("抽到的成员学号" + CLASS.get(s-1).member1.getId() + "，姓名" + CLASS.get(s-1).member1.getName());
                    this.getContentPane().add(information);
                } else {
                    InitImage();
                    information.setBounds(320, 150, 300, 100);
                    information.setText("抽到的成员学号" + CLASS.get(s-1).member2.getId() + "，姓名" + CLASS.get(s-1).member2.getName());
                    this.getContentPane().add(information);
                }
            } else {
                InitImage();
                information.setBounds(320, 150, 200, 100);
                information.setText("要抽取的的小组不存在");
                this.getContentPane().add(information);
            }
        }else if(obj==confirm9){
            int tmp = getNum(input12.getText());
            if (JudgeClass(RealCLASS, tmp) && IsStudent(arr, tmp)) {
                Random r = new Random();
                boolean flag = true;
                while (flag) {
                    int index = r.nextInt(arr.length);
                    if (arr[index].getaClass().getaClass() == tmp) {
                        InitImage();
                        information.setBounds(300, 150, 300, 100);
                        information.setText("抽到的学生学号为" + arr[index].getId() + "，姓名" + arr[index].getName());
                        this.getContentPane().add(information);
                        flag = false;
                    }
                }
            }else{
                InitImage();
                information.setBounds(320, 150, 200, 100);
                information.setText("班级不存在或没有添加学生");
                this.getContentPane().add(information);
            }
        }else if(obj==confirm10){
            String input = input13.getText();
            boolean flag1 = true;
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] != null) {
                    if (arr[i].getId().equals(input)) {
                        arr[i].attend++;
                        flag1 = false;
                        InitImage();
                        information.setBounds(320, 150, 200, 100);
                        information.setText("记录成功");
                        this.getContentPane().add(information);
                        break;
                    }
                }
            }
            if (flag1) {
                InitImage();
                information.setBounds(320, 150, 200, 100);
                information.setText("不存在的学生");
                this.getContentPane().add(information);
            }
        }else if(obj==confirm11){
            System.out.println("输入学生学号");
            String input = input14.getText();
            boolean flag1 = true;
            for (int i = 0; i < arr.length; i++) {
                if (arr[i] != null) {
                    if (arr[i].getId().equals(input)) {
                        arr[i].answer++;
                        flag1 = false;
                        InitImage();
                        information.setBounds(320, 150, 200, 100);
                        information.setText("记录成功");
                        this.getContentPane().add(information);
                        break;
                    }
                }
            }
            if (flag1) {
                InitImage();
                information.setBounds(320, 150, 200, 100);
                information.setText("不存在的学生");
                this.getContentPane().add(information);
            }
        }else if(obj==confirm12){
            System.out.println("请输入小组编号");
            int index = getNum(input15.getText());
            if (index < CLASS.size()) {
                CLASS.get(index-1).score= getNum(input16.getText());
                InitImage();
                information.setBounds(320, 150, 200, 100);
                information.setText("记录成功");
                this.getContentPane().add(information);
            } else {
                InitImage();
                information.setBounds(320, 150, 200, 100);
                information.setText("小组不存在");
                this.getContentPane().add(information);
            }
        }
    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }


    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }


    public static int Judge(Student[] arr) {
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != null) {
                count++;
            }
        }
        return count;
    }

    public static Student[] Creat(Student[] arr) {
        Student[] arr1 = new Student[arr.length + 1];
        for (int i = 0; i < arr.length; i++) {
            arr1[i] = arr[i];
        }
        arr1[arr1.length - 1] = new Student();
        return arr1;
    }

    public static boolean JudgeOnly(Student[] arr, String input) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != null) {
                if (arr[i].getId() != null) {
                    if (arr[i].getId().equals(input)) {
                        return false;
                    }
                }
            }
        }
        return true;
    }

    public static boolean JudgeClass(ArrayList<aClass> c, int a) {
        for (int i = 0; i < c.size(); i++) {
            if (c.get(i).getaClass() == a) {
                return true;
            }
        }
        return false;
    }

    public static boolean IsStudent(Student[] arr, int a) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getaClass().getaClass() == a) {
                return true;
            }
        }
        return false;
    }

    public static void DeleteClass(Student[] arr, int a) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].getaClass().getaClass() == a) {
                arr[i] = null;
            }
        }
    }

    public static void DeleteRealCLASS(ArrayList<aClass> list, int tmp) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getaClass() == tmp) {
                list.remove(i);
            }
        }
    }

    public static int getNum(String o) {
        int sum = 0;
        for (int i = 0; i < o.length(); i++) {
            int a = o.charAt(i) - '0';
            sum = sum * 10 + a;
        }
        return sum;
    }
}
